#ifndef GY_LISTENERHELPER_H
#define GY_LISTENERHELPER_H

#include "GY_ControlLibrary_global.h"
#include <QObject>
#include <QPair>
#include <QMap>
#include <QVariant>
#include <QByteArray>
#include <QPointer>

#define LHCB(a)  (#a)

typedef QPair<QPointer<QObject>, const char*> Hander;

class GY_CONTROLLIBRARY_EXPORT GY_ListenerHelper
{
public:
    GY_ListenerHelper();

    /**
     * @brief addListener 添加监听对象
     * @param eventName 事件名称
     * @param receiver 对象
     * @param methodName 方法名称
     */
    static void addListener(const QString &eventName, QObject* pReceiver, const char* pMethodName);
    /**
     * @brief removeListener 移除监听对象
     * @param receiver 对象
     */
    static void removeListener(QObject* pReceiver);
    /**
     * @brief emitEvent 事件响应
     * @param eventName 事件名称
     * @param data 数据
     */
    static void emitEvent(const QString &eventName, const QVariant &data = QVariant());

private:
    static QMap<QString, QList<Hander>> m_listenerMap;
};

#endif // GY_LISTENERHELPER_H
